//课设LED广告
#include <reg51.h>
#include <intrins.h>
#define u8 unsigned char
#define u16	unsigned int

sbit SER=P3^4;    //串口
sbit RCLK=P3^5;	  //锁存寄存器
sbit SRCLK=P3^6;   // 串口同步信号
//code u16 TAB2[6] = {0x43,0x87,0x8D,0x99,0x91,0x63};

void delay_ms(u16 x)
{
	u8 t;
	while(x--){
		for(t=0;t<100;t++);
	}
}

void hc595_send_high_first(u16 dat){
// 高位优先传入
	int i;
	SRCLK=0;
	for(i=0;i<16;i++){
		SER=dat>>7;
		dat=dat<<1;
		//SER=dat>>i;
		SRCLK=0;
		_nop_();_nop_();
		SRCLK=1;
		_nop_();_nop_();
	}
	RCLK=0;
	_nop_();_nop_();
	RCLK=1;
	_nop_();_nop_();
}


void hc595_send_low_first(u16 dat){
// 低位优先传入
	int i;
	for(i=0;i<16;i++){
		SER=dat<<15;
		dat=dat>>1;
		SRCLK=0;
		_nop_();
		SRCLK=1;
		_nop_();
	}
	RCLK=0;
	_nop_();
	RCLK=1;
	_nop_();
}

void main(){
	u8 out_side;
	//u16 TAB0[6] = {0xFF,0xFF,0xC3,0xC3,0xFF,0xFF};
	//u16 TAB1[6] = {0x01,0x41,0xFF,0xFF,0x01,0x01};
	//u16 TAB2[6] = {0x43,0x87,0x8D,0x99,0x91,0x63};
	//u16 TAB3[6] = {0x42,0x91,0x91,0x91,0x91,0xEE};
	//u16 TAB4[6] = {0x1C,0x24,0x44,0xFF,0x04,0x04};
	//u16 TAB5[6] = {0xF6,0x91,0x91,0x91,0x91,0x8E};
	
	u16 test[16] = {0x00F0,0x0F00,0xF000,0x000F,0x0006,0x0060,0x0600,0x6000,0x00F0,0x0F00,0xF000,0x000F,0x0006,0x0060,0x0600,0x6000};
	u16* TAB_addr[1] = {&test}; // 存放阵列阴极行码数组地址
	u16 *TAB; // 阳极码数组指针
	int delay_s =1;
	int i;
	int num;
	int time;
	while (1){
		for(num=0;num<1;num++){
			TAB = TAB_addr[num];  //选用阴极行码数组
			for(time=0;time<50;time++){
				out_side = 0x00; //阳极 列 
				for(i=0;i<16;i++){
					//u8 temp=out_side; // 传入行码
					//hc595_send_low_first(temp);
					//P0=*(TAB+i); //阳 行(高位在上)
					hc595_send_low_first(*(TAB+i));	//阴极,行(高位在上)
					P2=out_side	
					out_side++;
				//	delay_ms(delay_s);
					
				}
				
			}
			P2=0x00; // 消隐
		}
	}
}
